<?php

/**
 * ContactForm class.
 * ContactForm is the data structure for keeping
 * contact form data. It is used by the 'contact' action of 'SiteController'.
 */
class ContactForm extends CFormModel
{
	public $name;
	public $email;
	public $subject;
	public $body;
	public $verifyCode;

	/**
	 * Declares the validation rules.
	 */
	public function rules()
	{
		return array(
			// name, email, subject and body are required
			array('name, email, subject, body', 'required'),
			// email has to be a valid email address
			array('email', 'email'),
			// verifyCode needs to be entered correctly
			array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
		);
	}

	/**
	 * Declares customized attribute labels.
	 * If not declared here, an attribute would have a label that is
	 * the same as its name with the first letter in upper case.
	 */
	public function attributeLabels()
	{
		return array(
			'verifyCode'=>'Kod weryfikacyjny',
                        'name'=>'Imię i nazwisko',
                        'email'=>'Twój e-mail',
                        'subject'=>'Temat',
                        'body'=>'Treść',
		);
	}

        public function send()
	{
		$message = new YiiMailMessage;
                $message->subject = $this->subject;
                $message->setBody($this->body, 'text/html');
                //$id_admin=1;
                //$record=Osoba::model()->findByAttributes(array('id_uzytkownik'=>$id_admin));
                $message->addTo(Yii::app()->params['adminEmail']);
                //if (isset($this->email))
                //    $message->addTo('adminEmail');
                //else {
                //    $record=Osoba::model()->findByAttributes(array('id_uzytkownik'=>$this->id_adresat));
                //    $message->addTo('adminEmail');
                //}

                //$record=Osoba::model()->findByAttributes(array('id_uzytkownik'=>$this->id_nadawca));
                $message->from = $this->email;

                Yii::app()->mail->send($message);

                Yii::app()->user->setFlash('contact','Dziękujemy za kontakt. Postaramy się odpowiedzieć tak szybko, jak to możliwe.');
                //return $this->save();
	}
}